package org.dtrd.modules.flup.entity.po;

import com.baomidou.mybatisplus.annotation.*;
import lombok.Getter;
import lombok.Setter;
import lombok.SneakyThrows;
import org.dtrd.common.util.DateUtils;
import org.dtrd.modules.flup.entity.bean.FlupAppointmentRecordDetail;
import org.dtrd.modules.flup.entity.request.PatientFlup;

import java.util.Date;


/**
 * <p>
 * 复诊预约记录
 * </p>
 *
 * @author QR
 * @since 2021-12-16
 */
@Getter
@Setter
@TableName("dtrd_ent_rd_flup_appointment_record")
public class DtrdEntRdFlupAppointmentRecord {

    @TableId(value = "data_id", type = IdType.AUTO)
    private Integer dataId;

    /**
     * 机构编码
     */
    @TableField("org_code")
    private String orgCode;

    /**
     * 医生id
     */
    @TableField("doctor_id")
    private Integer doctorId;

    /**
     * 患者id
     */
    @TableField("patient_id")
    private Integer patientId;

    /**
     * 复诊预约日期
     */
    @TableField("flup_date")
    private Date flupDate;

    /**
     * 复诊预约时间段
     */
    @TableField("flup_time")
    private Integer flupTime;

    @TableField("flup_real_start_time")
    private Date flupRealStartTime;

    @TableField("flup_real_end_time")
    private Date flupRealEndTime;

    /**
     * 复诊模版id
     */
    @TableField("flup_template_id")
    private Integer flupTemplateId;

    /**
     * 复诊状态, 0-未预约, 1-待复诊, 2-已复诊, 3-未复诊, 4-复诊中
     */
    @TableField("flup_status")
    private Integer flupStatus;

    /**
     * 接待人
     */
    @TableField("receiver")
    private String receiver;

    /**
     * 备注
     */
    @TableField("remark")
    private String remark;

    @TableField("is_del")
    @TableLogic
    private Integer isDel;

    @TableField("create_time")
    private Date createTime;

    @TableField("update_time")
    private Date updateTime;

    @TableField("flup_content")
    private String flupContent;

    public DtrdEntRdFlupAppointmentRecord init() {
        isDel = 0;
        createTime = new Date();
        return this;
    }

    public DtrdEntRdFlupAppointmentRecord parseFromDto(FlupAppointmentRecordDetail dto) {
        dataId = dto.getDataId();
        orgCode = dto.getOrgCode();
        doctorId = dto.getDoctorId();
        patientId = dto.getPatientId();
        flupDate = dto.getFlupDate();
        flupTime = dto.getFlupTime();
        flupTemplateId = dto.getFlupTemplateId();
        remark = dto.getRemark();
        flupContent = dto.getFlupContent();
        return this;
    }

    @SneakyThrows
    public DtrdEntRdFlupAppointmentRecord parseFromDto(PatientFlup dto) {
        dataId = dto.getDataId();
        doctorId = dto.getDoctorId();
        patientId = dto.getPatientId();
        flupTemplateId = dto.getTemplateId();
        flupDate = DateUtils.parseDate(dto.getFlupDate(), DateUtils.date_sdf.get().toPattern());
        flupTime = dto.getFlupTime();
        receiver = dto.getReceiver();
        remark = dto.getRemark();
        orgCode = dto.getOrgCode();
        return this;
    }


}
